<?php 
    defined('_JEXEC') or die('Restricted access');
	jimport('joomla.application.component.model');
	class work_pointModeldashboard extends JModel
	{
	   function report_date($date=null)
       {
            //neu date = null thi lay ngay hien hanh
            if($date == null)
            {
                $date = date('Y-m-d');
            }
            //dinh dang lai $date giong voi CSDL
            else
            {
                $d = substr($date,3,2);
                $m = substr($date,0,2);
                $y = substr($date,6,4);
                $date = $y."-".$m."-".$d;
                
            }
            $db = JFactory::getDBO();
            if($_SESSION['id_a_b']==0)
            {
                $sql = "select us.name, us.id, ts.type_in_out, ts.Time, pf.id_employee, ab.id_a_b
                        from  #__erp_employee_profile pf
                        left join #__erp_agent_branch_user ab
                        on ab.id_user = pf.id
                        INNER JOIN #__users us
                                    on us.id = pf.id
                        inner join #__erp_timesheet ts
                            on ts.id_user = pf.id
                        where ts.Time LIKE '$date%'
                        order by ts.Time
                                            ";
                $db->setQuery($sql);
                //print_r($db);die;
                $rs= $db->loadObjectList();
                return $rs;
            }
            else
            {
                $sql = "select us.name, us.id, ts.type_in_out, ts.Time, pf.id_employee, ab.id_a_b
                        from  #__erp_employee_profile pf
                        left join #__erp_agent_branch_user ab
                        on ab.id_user = pf.id
                        INNER JOIN #__users us
                                    on us.id = pf.id
                        inner join #__erp_timesheet ts
                            on ts.id_user = pf.id
                        where ts.Time LIKE '$date%'
                        and ab.id_a_b = '".$_SESSION['id_a_b']."'
                        order by ts.Time
                                            ";
                $db->setQuery($sql);
                //print_r($db);die;
                $rs= $db->loadObjectList();
                return $rs;
            }
       }
	}
?>